use async_trait::async_trait;
use crate::model::LogEntry;
use crate::config::Config;
use anyhow::Result;

#[async_trait]
pub trait LogStorage: Send + Sync {
    async fn store(&self, log: LogEntry) -> Result<()>;
    async fn query(&self, filter: LogFilter) -> Result<Vec<LogEntry>>;
}

pub enum StorageType {
    Memory,
    Elastic,
    Database,
}

pub fn create_storage(config: &Config) -> Result<Box<dyn LogStorage>> {
    match config.storage.storage_type {
        StorageType::Memory => Ok(Box::new(MemoryStorage::new(config))),
        StorageType::Elastic => Ok(Box::new(ElasticStorage::new(config)?)),
        StorageType::Database => Ok(Box::new(DatabaseStorage::new(config)?)),
    }
}